package com.hmall.user.web;

import com.hmall.common.thread.UserThreadLocal;
import com.hmall.user.pojo.User;
import com.hmall.user.service.IUserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private IUserService userService;

    /**
     * 根据id查询用户信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public User getUser(@PathVariable Long id){
        User user = userService.getById(id);

        //直接从threadLocal中获取用户iD
        com.hmall.common.thread.User user1 = UserThreadLocal.getUser();
        System.out.println(user1);

        return user;
    }
}
